package ui2;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JSeparator;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;

public class PanelQueue extends JPanel {
	
	private static final long serialVersionUID = -3585458997394568117L;
	private JFrame frame;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					PanelQueue window = new PanelQueue();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public PanelQueue(	double iSubmission, 
						int iSize, 
						int eSize, 
						int iMaxThread, 
						int eMaxThread, 
						int iTimeout,
						int eTimeout) {
		super();
		initialize(	iSubmission, iSize, eSize, iMaxThread, eMaxThread, iTimeout, eTimeout);
	}

	public PanelQueue()
	{
		super();
		initialize(0.5, 5, 4, 5, 6, 1000, 2000);
	}
	
	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize(double iSubmission, 
							int iSize, 
							int eSize, 
							int iMaxThread, 
							int eMaxThread, 
							int iTimeout,
							int eTimeout) {
		frame = new JFrame();
		frame.setBounds(100, 100, 800, 550);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		//JPanel panelQueue = new JPanel();
		frame.getContentPane().add(this, BorderLayout.CENTER);
		GridBagLayout gbl_panelQueue = new GridBagLayout();
		gbl_panelQueue.columnWidths = new int[]{40, 141, 167, 35, 108, 210, 54, 40, 0};
		gbl_panelQueue.rowHeights = new int[]{48, 17, 59, 29, 62, 40, 21, 40, 0, 40, 0, 40, 0, 0};
		gbl_panelQueue.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_panelQueue.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		this.setLayout(gbl_panelQueue);
		
		JLabel label = new JLabel("Settings of your personal queue: size, timeout and number of elements");
		label.setForeground(Color.RED);
		label.setFont(new Font("Tahoma", Font.BOLD, 15));
		GridBagConstraints gbc_label = new GridBagConstraints();
		gbc_label.fill = GridBagConstraints.VERTICAL;
		gbc_label.insets = new Insets(0, 0, 5, 5);
		gbc_label.gridwidth = 6;
		gbc_label.gridx = 1;
		gbc_label.gridy = 1;
		this.add(label, gbc_label);
		
		JSeparator separator = new JSeparator();
		GridBagConstraints gbc_separator = new GridBagConstraints();
		gbc_separator.anchor = GridBagConstraints.NORTH;
		gbc_separator.fill = GridBagConstraints.HORIZONTAL;
		gbc_separator.insets = new Insets(0, 0, 5, 5);
		gbc_separator.gridwidth = 6;
		gbc_separator.gridx = 1;
		gbc_separator.gridy = 2;
		this.add(separator, gbc_separator);
		
		JLabel label_1 = new JLabel("I_submission");
		label_1.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
		GridBagConstraints gbc_label_1 = new GridBagConstraints();
		gbc_label_1.anchor = GridBagConstraints.EAST;
		gbc_label_1.insets = new Insets(0, 0, 5, 5);
		gbc_label_1.gridx = 1;
		gbc_label_1.gridy = 3;
		this.add(label_1, gbc_label_1);
		
		final JLabel lblDynamicValue = new JLabel("50%");
		GridBagConstraints gbc_label_2 = new GridBagConstraints();
		gbc_label_2.anchor = GridBagConstraints.WEST;
		gbc_label_2.insets = new Insets(0, 0, 5, 5);
		gbc_label_2.gridx = 6;
		gbc_label_2.gridy = 3;
		this.add(lblDynamicValue, gbc_label_2);
    	
    	JSlider slider_1 = new JSlider();
    	GridBagConstraints gbc_slider = new GridBagConstraints();
		gbc_slider.anchor = GridBagConstraints.NORTH;
		gbc_slider.fill = GridBagConstraints.HORIZONTAL;
		gbc_slider.insets = new Insets(0, 0, 5, 5);
		gbc_slider.gridwidth = 4;
		gbc_slider.gridx = 2;
		gbc_slider.gridy = 3;
    	ChangeListener sizeAction2=new ChangeListener(){
            public void stateChanged (ChangeEvent event){
                JSlider slider=(JSlider)event.getSource();
                int value = slider.getValue();
	        	lblDynamicValue.setText(""+value+"%");
            }
        };
        slider_1.addChangeListener(sizeAction2);
    	this.add(slider_1, gbc_slider);
		
		JLabel label_3 = new JLabel("isize");
		label_3.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
		GridBagConstraints gbc_label_3 = new GridBagConstraints();
		gbc_label_3.anchor = GridBagConstraints.EAST;
		gbc_label_3.fill = GridBagConstraints.VERTICAL;
		gbc_label_3.insets = new Insets(0, 0, 5, 5);
		gbc_label_3.gridx = 1;
		gbc_label_3.gridy = 5;
		this.add(label_3, gbc_label_3);
		
		textField = new JTextField(iSize);
		textField.setColumns(10);
		GridBagConstraints gbc_textField = new GridBagConstraints();
		gbc_textField.anchor = GridBagConstraints.SOUTH;
		gbc_textField.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField.insets = new Insets(0, 0, 5, 5);
		gbc_textField.gridx = 2;
		gbc_textField.gridy = 5;
		this.add(textField, gbc_textField);
		
		JLabel label_6 = new JLabel("Task timeout:");
		label_6.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
		GridBagConstraints gbc_label_6 = new GridBagConstraints();
		gbc_label_6.anchor = GridBagConstraints.SOUTHEAST;
		gbc_label_6.insets = new Insets(0, 0, 5, 5);
		gbc_label_6.gridx = 4;
		gbc_label_6.gridy = 6;
		this.add(label_6, gbc_label_6);
		
		textField_3 = new JTextField(iTimeout);
		textField_3.setColumns(10);
		GridBagConstraints gbc_textField_3 = new GridBagConstraints();
		gbc_textField_3.anchor = GridBagConstraints.NORTH;
		gbc_textField_3.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_3.insets = new Insets(0, 0, 5, 5);
		gbc_textField_3.gridheight = 2;
		gbc_textField_3.gridx = 5;
		gbc_textField_3.gridy = 6;
		this.add(textField_3, gbc_textField_3);
		
		JLabel label_4 = new JLabel("esize");
		label_4.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
		GridBagConstraints gbc_label_4 = new GridBagConstraints();
		gbc_label_4.anchor = GridBagConstraints.EAST;
		gbc_label_4.fill = GridBagConstraints.VERTICAL;
		gbc_label_4.insets = new Insets(0, 0, 5, 5);
		gbc_label_4.gridx = 1;
		gbc_label_4.gridy = 7;
		this.add(label_4, gbc_label_4);
		
		textField_1 = new JTextField(eSize);
		textField_1.setColumns(10);
		GridBagConstraints gbc_textField_1 = new GridBagConstraints();
		gbc_textField_1.anchor = GridBagConstraints.SOUTH;
		gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_1.insets = new Insets(0, 0, 5, 5);
		gbc_textField_1.gridx = 2;
		gbc_textField_1.gridy = 7;
		this.add(textField_1, gbc_textField_1);
		
		JLabel label_5 = new JLabel("N\u00B0 Task max:");
		label_5.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
		GridBagConstraints gbc_label_5 = new GridBagConstraints();
		gbc_label_5.anchor = GridBagConstraints.EAST;
		gbc_label_5.fill = GridBagConstraints.VERTICAL;
		gbc_label_5.insets = new Insets(0, 0, 5, 5);
		gbc_label_5.gridx = 1;
		gbc_label_5.gridy = 9;
		this.add(label_5, gbc_label_5);
		
		textField_2 = new JTextField(iMaxThread);
		textField_2.setColumns(10);
		GridBagConstraints gbc_textField_2 = new GridBagConstraints();
		gbc_textField_2.anchor = GridBagConstraints.SOUTH;
		gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_2.insets = new Insets(0, 0, 5, 5);
		gbc_textField_2.gridx = 2;
		gbc_textField_2.gridy = 9;
		this.add(textField_2, gbc_textField_2);
		
		JLabel label_8 = new JLabel("Event Timeout:");
		label_8.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
		GridBagConstraints gbc_label_8 = new GridBagConstraints();
		gbc_label_8.anchor = GridBagConstraints.NORTHEAST;
		gbc_label_8.insets = new Insets(0, 0, 5, 5);
		gbc_label_8.gridx = 4;
		gbc_label_8.gridy = 9;
		this.add(label_8, gbc_label_8);
		
		textField_5 = new JTextField(eTimeout);
		textField_5.setColumns(10);
		GridBagConstraints gbc_textField_5 = new GridBagConstraints();
		gbc_textField_5.anchor = GridBagConstraints.NORTH;
		gbc_textField_5.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_5.insets = new Insets(0, 0, 5, 5);
		gbc_textField_5.gridx = 5;
		gbc_textField_5.gridy = 9;
		this.add(textField_5, gbc_textField_5);
		
		JLabel label_7 = new JLabel("N\u00B0 Event max:");
		label_7.setFont(new Font("Lucida Grande", Font.PLAIN, 15));
		GridBagConstraints gbc_label_7 = new GridBagConstraints();
		gbc_label_7.anchor = GridBagConstraints.EAST;
		gbc_label_7.fill = GridBagConstraints.VERTICAL;
		gbc_label_7.insets = new Insets(0, 0, 5, 5);
		gbc_label_7.gridx = 1;
		gbc_label_7.gridy = 11;
		this.add(label_7, gbc_label_7);
		
		textField_4 = new JTextField(eMaxThread);
		textField_4.setColumns(10);
		GridBagConstraints gbc_textField_4 = new GridBagConstraints();
		gbc_textField_4.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_4.insets = new Insets(0, 0, 5, 5);
		gbc_textField_4.gridx = 2;
		gbc_textField_4.gridy = 11;
		this.add(textField_4, gbc_textField_4);
		
		JButton button = new JButton("CONFIRM");
		GridBagConstraints gbc_button = new GridBagConstraints();
		gbc_button.anchor = GridBagConstraints.SOUTHWEST;
		gbc_button.insets = new Insets(0, 0, 5, 5);
		gbc_button.gridx = 5;
		gbc_button.gridy = 11;
		this.add(button, gbc_button);
	}

}
